package net.zjitc.utils;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/8.
 */
public class ControllerUtils {
    public static List getClass(String packageName) throws ClassNotFoundException {
        List<Class> list = new ArrayList();
        String pathName = packageName.replace(".","/");
        URL resource = Thread.currentThread().getContextClassLoader().getResource(pathName);
        File file = new File(resource.getPath());
        File[] files = file.listFiles();
        for (File f:files) {
           if(f.getName().endsWith(".class")){//判断后缀名是否是.class
               String className =packageName+"."+f.getName().substring(0,f.getName().length()-6);//拼接完整类名
               Class clazz = Class.forName(className);//通过类名获得类对象
               list.add(clazz);//把类添加到集合中
           }
        }
        return list;
    }
}
